package com.example.management.common.service.impl

import com.example.management.common.config.BootdoConfig
import com.example.management.common.dao.FileDao
import com.oracle.util.Checksums.update
import com.example.management.common.domain.FileDO
import org.springframework.beans.factory.annotation.Autowired
import com.example.management.common.service.FileService
import org.apache.commons.lang.StringUtils
import org.springframework.stereotype.Service
import java.io.File


@Service
class FileServiceImpl : FileService {
    @Autowired
    private val sysFileMapper: FileDao? = null

    @Autowired
    private val bootdoConfig: BootdoConfig? = null

    override fun get(id: Long?): FileDO {
        return sysFileMapper!!.get(id)
    }

    override fun list(map: Map<String, Any>): List<FileDO> {
        return sysFileMapper!!.list(map)
    }

    override fun count(map: Map<String, Any>): Int {
        return sysFileMapper!!.count(map)
    }

    override fun save(sysFile: FileDO): Int {
        return sysFileMapper!!.save(sysFile)
    }

    override fun update(sysFile: FileDO): Int {
        return sysFileMapper!!.update(sysFile)
    }

    override fun remove(id: Long?): Int {
        return sysFileMapper!!.remove(id)
    }

    override fun batchRemove(ids: Array<Long>): Int {
        return sysFileMapper!!.batchRemove(ids)
    }

    override fun isExist(url: String?): Boolean? {
        var isExist: Boolean? = false
        if (!StringUtils.isEmpty(url)) {
            var filePath = url!!.replace("/files/", "")
            filePath = bootdoConfig!!.uploadPath + filePath
            val file = File(filePath)
            if (file.exists()) {
                isExist = true
            }
        }
        return isExist
    }
}
